﻿using codeparser.net.v2.Aspects;
using codeparser.net.v2.Entities;

using System;

namespace codeparser.net.v2.Validators
{
    /// <summary>
    /// Represents an abstract base class for a token validator strategy.
    /// </summary>
    internal abstract class TokenValidatorStrategyBase
    {
        /// <summary>
        /// Validates the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="tagConfiguration">The tag configuration.</param>
        [LoggingAspect]
        internal void Validate(Token token, TagConfiguration tagConfiguration)
        {
            // Validate the token depending on the token type.
            switch (token.Type)
            {
                case TokenType.Element:
                    token.Tag = this.ValidateElement(token, tagConfiguration);
                    break;
                case TokenType.Attribute:
                    this.ValidateAttribute(token, tagConfiguration);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// Validates the specified element token.
        /// </summary>
        /// <param name="token">The element token.</param>
        /// <param name="tagConfiguration">The tag configuration.</param>
        /// <returns>The tag.</returns>
        [LoggingAspect]
        internal virtual Tag ValidateElement(Token token, TagConfiguration tagConfiguration)
        {
            return null;
        }

        /// <summary>
        /// Validates the specified attribute token.
        /// </summary>
        /// <param name="token">The attribute token.</param>
        /// <param name="tagConfiguration">The tag configuration.</param>
        [LoggingAspect]
        internal virtual void ValidateAttribute(Token token, TagConfiguration tagConfiguration)
        {
        }

        /// <summary>
        /// Validates the specified attribute token.
        /// </summary>
        /// <param name="token">The attribute token.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="attribute">The attribute as out parameter.</param>
        [LoggingAspect]
        internal virtual void ValidateAttribute(Token token, Tag tag, out TagAttribute attribute)
        {
            attribute = null;
        }
    }
}